#include "widget.h"
#include "ui_widget.h"
#include <QRect>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{

}

void Widget::on_pushButton_down_clicked()
{
    QRect rect = this->ui->pushButton_target->geometry();
    //QRect内部只是存了当前元素的左上和右下两个坐标，再通过这两个点的坐标差值计算长宽
    //这样设置会导致控件的长宽发生变化
//    rect.setY(rect.y() + 5);
//    this->ui->pushButton_target->setGeometry(rect);
    this->ui->pushButton_target->setGeometry(rect.x(),rect.y() + 5,rect.width(),rect.height());
}


void Widget::on_pushButton_left_clicked()
{
    QRect rect = this->ui->pushButton_target->geometry();
//    rect.setX(rect.x() - 5);
//    this->ui->pushButton_target->setGeometry(rect);
    this->ui->pushButton_target->setGeometry(rect.x() - 5,rect.y(),rect.width(),rect.height());
}

void Widget::on_pushButton_right_clicked()
{
    QRect rect = this->ui->pushButton_target->geometry();
//    rect.setX(rect.x() + 5);
//    this->ui->pushButton_target->setGeometry(rect);
    this->ui->pushButton_target->setGeometry(rect.x() + 5,rect.y(),rect.width(),rect.height());
}

void Widget::on_pushButton_up_clicked()
{
    QRect rect = this->ui->pushButton_target->geometry();
//    rect.setY(rect.y() - 5);
//    this->ui->pushButton_target->setGeometry(rect);
    this->ui->pushButton_target->setGeometry(rect.x(),rect.y() - 5,rect.width(),rect.height());
}
